package com.rst.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rst.model.ClassTiming;
import com.rst.model.Classe;
import com.rst.model.TimeTable;
import com.rst.model.Weekday;

@Repository
@Transactional
public class TimeTableDAO {

	@Autowired
	private SessionFactory sessionFactory;


	@SuppressWarnings("unchecked")
	public List<Weekday> getweekdays() {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Weekday.class);
		return criteria.list();
	}

	public Long save(Weekday weekday) {
		return (Long) sessionFactory.getCurrentSession().save(weekday);	
	}

	@SuppressWarnings("unchecked")
	public List<ClassTiming> getclassTimingList() {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ClassTiming.class);
		return criteria.list();
	}

	public Long saveClassTiming(ClassTiming classTiming) {
		return (Long) sessionFactory.getCurrentSession().save(classTiming);	
	}

	public ClassTiming getClasstimingById(Long classTimingId) {
	    Session session = sessionFactory.getCurrentSession();
	    ClassTiming classTiming = (ClassTiming)session.get(ClassTiming.class, classTimingId);
		return classTiming;
	}

	public Long saveTimeTable(TimeTable timeTable) {
		return (Long) sessionFactory.getCurrentSession().save(timeTable);	
	}

	@SuppressWarnings("unchecked")
	public List<ClassTiming> getClasstimingBySectionId(Long sectionId) {
		Session session = sessionFactory.getCurrentSession();
	    String str = "FROM ClassTiming c WHERE c.sectionId = :sectionId  AND c.status = :status  ";
	    	
	    Query query = session.createQuery(str);
	    query.setParameter("status",  Classe.ACTIVE);
	    query.setParameter("sectionId",  sectionId);
		return query.list();
	}

	public Weekday getClassWeekdaysBySectionId(Long sectionId) {
	    Session session = sessionFactory.getCurrentSession();
	    Weekday weekday = (Weekday)session.get(Weekday.class, sectionId);
		return weekday;
	}
}




